package com.dkm.controller;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.dkm.entity.DynamicMessage;
import com.dkm.entity.SignInLog;
import com.dkm.service.DynamicMessageService;
import com.dkm.service.SignInLogService;
import com.dkm.util.ResultUtil;

@RestController
@RequestMapping("/hint")
public class HintController {

	//注入签到日志业务
	@Autowired
	private SignInLogService signInLogService;
	
	//注入动态消息业务
	@Autowired
	private DynamicMessageService dynamicMessageService;
	
	SimpleDateFormat timestampsdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
	SimpleDateFormat datesdf=new SimpleDateFormat("yyyy-MM-dd");
	
	//签到提示
	@GetMapping("/hintSignin")
	public ResultUtil hintSignin(String user_id) {
		//获取当前时间
		Date date=new Date();
		//获取该用户今天的签到信息
		String d=datesdf.format(date);
		try {
			SignInLog sl = signInLogService.getSignInLogByUser_idAndDate(user_id,timestampsdf.parse(d+" 00:00:00") ,timestampsdf.parse(d+" 23:59:59"));
			//如果日志信息不为空
			if(sl!=null) {
				return new ResultUtil(-1, "今天已完成签到！", sl);
			}
			return new ResultUtil(0, "今天还没有签到！", null);
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return new ResultUtil(-1, "日期转换异常，无法提示", null);
		}
	}
	
	//未读动态消息提示
	@GetMapping("/UnreadDynamicMessage")
	public ResultUtil UnreadDynamicMessage(String login_name) {
		List<DynamicMessage> dynamicMessages=dynamicMessageService.getUnreadDynamicMessage(login_name);
	
		if(dynamicMessages.size()>0) {
			return new ResultUtil(0, "你有"+dynamicMessages.size()+"条动态未读", dynamicMessages.size());
		}
		return new ResultUtil(-1, "暂无未读消息", null);
	}
}
